package com.biz.primus.ms.commodity.trans;

import com.biz.primus.base.enums.commodity.IStatus;
import com.biz.primus.commodity.vo.backend.BrandVo;
import com.biz.primus.ms.commodity.dao.po.Brand;
import com.biz.primus.ms.commodity.dao.po.Category;
import com.google.common.base.Function;

import java.util.List;

/**
 * @author 江南
 * @usage
 * @reviewer
 * @since 2016/12/19
 */
public class BrandVo2Brand implements Function<BrandVo, Brand> {

    private Brand brand;

    private List<Category> categoryList;

    public BrandVo2Brand(Brand brand, List<Category> categoryList) {
        this.brand = brand;
        if (brand == null){
            this.brand = new Brand();
        }
        this.categoryList = categoryList;
    }

    @Override
    public Brand apply(BrandVo input) {
        brand.setId(Long.valueOf(input.getId()));
        brand.setName(input.getName());
        brand.setLogo(input.getLogo());
        brand.setIdx(input.getIdx());
        brand.setCategories(categoryList);
        brand.setStatus(input.getStatus() == IStatus.DELETE.getValue() ? IStatus.DELETE : IStatus.NORMAL);
        return brand;
    }
}
